package com.example.controller;

import com.alibaba.excel.EasyExcel;
import com.example.entity.*;
import com.example.getdata.DataFromJiaoTong;
import com.example.mapper.ObjMapper;
import com.example.mapper.RoadtransportvehiclesMapper;
import com.example.service.*;
import com.example.vo.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.io.File;
import java.time.LocalDate;
import java.util.*;

/*
 *  @author 雨安
 *  类名： ScheduledTaskController
 *  创建时间：2024/6/13
 */
@Slf4j
@RestController
@Api(tags = "数据推送更新时间8月06号(实时推送)")//前端查看api接口
public class ScheduledTaskController {

    @Autowired
    private ObjMapper objMapper;


    //稍后测试
    @Scheduled(cron = "0 00 01 * * *")
    @ApiOperation(value = "运政数据一键获取")//swagger2查看
    @GetMapping("/get/ir/data")
    public void doGetData() throws JsonProcessingException {
        //调用清空表格方法
        deleteAllIR();
        //调用查看清空状态方法
        selectAllInfo();
        //调用获取数据方法
        getAllData();
        //调用查看所有方法
        selectAllInfo();
    }

    //发送数据到腾讯云
    @Scheduled(cron = "0 02 02 * * *")
    @ApiOperation(value = "运政数据一键推送")//swagger2查看
    @GetMapping("/push/excel/tencent")
    public void doSendExcel(){
        //发送Excel方法

        /**
         * 一:  https://axd-1256474543.cos.ap-chongqing.myqcloud.com/axd业户基础信息.xlsx
         * 二:  https://axd-1256474543.cos.ap-chongqing.myqcloud.com/axd业户经营许可证基础信息.xlsx
         * 三:  https://axd-1256474543.cos.ap-chongqing.myqcloud.com/axd从业人员基础信息.xlsx
         * 四:  https://axd-1256474543.cos.ap-chongqing.myqcloud.com/axd从业资格证.xlsx
         * 五:  https://axd-1256474543.cos.ap-chongqing.myqcloud.com/axd本市重型普货车辆专题基础信息.xlsx
         * 六:  https://axd-1256474543.cos.ap-chongqing.myqcloud.com/axd道路运输经营许可信息.xlsx
         * 七:  https://axd-1256474543.cos.ap-chongqing.myqcloud.com/axd道路运输车辆基础信息.xlsx
         */
        handleExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\业户基础信息.xlsx","axd业户基础信息.xlsx");
        handleExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\业户经营许可证基础信息.xlsx","axd业户经营许可证基础信息.xlsx");
        handleExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\从业人员基础信息.xlsx","axd从业人员基础信息.xlsx");
        handleExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\从业资格证.xlsx","axd从业资格证.xlsx");
        handleExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\本市重型普货车辆专题基础信息.xlsx","axd本市重型普货车辆专题基础信息.xlsx");
        handleExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\道路运输经营许可信息.xlsx","axd道路运输经营许可信息.xlsx");
        handleExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\道路运输车辆基础信息.xlsx","axd道路运输车辆基础信息.xlsx");
    }


    /**
     * 2026-08-23	长期
     * 2024-06-24	2025-04-04
     * 2026-01-18	2028-01-19
     * 2027-06-20	2027-01-07
     * 2027-03-09	长期
     * 2025-03-31	2024-11-26
     * 2024-10-10	2031-11-24
     * 2026-07-14	2030-02-28
     * 2026-09-10	2029-05-20
     * 2028-04-23	2025-09-15
     * 2027-01-08	2026-01-08
     * 2024-12-17	长期
     */

    /**
     * 上传腾讯云数据方法
     */
    public void handleExcel(String filePath,String uploadFileName){
        // 替换为您的腾讯云账号的 SecretId 和 SecretKey
        String secretId = "AKIDzrX0EE0Vnwsd9RWNyKSLxKSLUO2SfdMq";
        String secretKey = "IBuSlrqiR1QipjPsENJ1WoshJhuufEYe";
        // 替换为您的腾讯云 COS 存储桶所在的地域
        String regionName = "ap-chongqing";
        // 替换为您的腾讯云 COS 存储桶名称
        String bucketName = "axd-1256474543";
        // 文件在 COS 中的路径和名称
        String key = uploadFileName;
        // 本地 Excel 文件路径
//        String filePath = "D:\\梦潮\\数据下载后端\\src\\main\\resources\\道路运输信息.xlsx";

        BasicCOSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
        // 设置 COS 存储桶的地域
        Region region = new Region(regionName);
        // 创建 COS 客户端配置
        ClientConfig clientConfig = new ClientConfig(region);
        // 创建 COS 客户端
        COSClient cosClient = new COSClient(cred, clientConfig);
        // 本地文件对象
        File localFile = new File(filePath);
        // 创建上传请求
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
        // 执行上传操作
        PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);

        // 获取上传文件的访问URL
        String fileUrl = "https://" + bucketName + ".cos." + regionName + ".myqcloud.com/" + key;
        //打印访问的 url
        System.out.println("文件上传成功，访问URL：" + fileUrl);
        // 关闭 COS 客户端
        cosClient.shutdown();
    }



    /**
     * 定时清空运政数据
     */
//    @ApiOperation(value = "数据获取失败一键删除(执行后可一键删除所有存储的数据)")//swagger2查看
//    @GetMapping("/deleteAllData")
    public void deleteAllIR(){
        objMapper.deleteHeaAll();
        objMapper.deleteHouseAll();
        objMapper.deleteOccAll();
        objMapper.deleteTranAll();
        objMapper.deleteRoadAll();
        objMapper.deletePraAll();
        objMapper.deleteBusAll();
    }

//    @ApiOperation(value = "查看获取数据情况")
//    @GetMapping("/select/all/info")
    public void selectAllInfo(){
        Integer integer = objMapper.selectHeaAll();
        System.out.println("selectHeaAll:" + integer);
        Integer integer1 = objMapper.selectBusAll();
        System.out.println("selectBusAll:" + integer1);
        Integer integer2 = objMapper.selectOccAll();
        System.out.println("selectOccAll:" + integer2);
        Integer integer3 = objMapper.selectPraAll();
        System.out.println("selectPraAll:" + integer3);
        Integer integer4 = objMapper.selectRoadAll();
        System.out.println("selectRoadAll:" + integer4);
        Integer integer5 = objMapper.selectTranAll();
        System.out.println("selectTranAll:" + integer5);
        Integer integer6 = objMapper.selectHouseAll();
        System.out.println("selectHouseAll:" + integer6);
    }


    @Autowired
    DataFromJiaoTong data;

    @Autowired
    PractitionerService practitionerService;

    @Autowired
    BusinessoperationService businessoperationService;

    @Autowired
    OccupationalrequirementsService occupationalrequirementsService;

    @Autowired
    HouseholdinformationService householdinformationService;

    @Autowired
    HeavygeneralcargoService heavygeneralcargoService;

    @Autowired
    RoadtransportService roadtransportService;

    @Autowired
    RoadtransportvehiclesService roadtransportvehiclesService;

    //数据获取IR自动执行代码
//    @GetMapping("/getData")//访问后缀名
//    @ApiOperation(value = "运政数据一键获取")//swagger2查看
    String getAllData() throws JsonProcessingException {
//        try{
            System.out.println("正在获取数据");
            //调用 从业人员基础信息
            Practitioner();
            //调用 业户经营许可证基础信息
            Businessoperation();
            //调用 从业资格证信息
            Occupationalrequirements();
            //调用 业户基础信息
            Householdinformation();
            //调用 本市重型普货车辆专题基础信息
            Heavygeneralcargo();
            //调用 道路运输经营许可信息
            Roadtransport();
            //调用 道路运输车辆基础信息
            Roadtransportvehicles();
            log.info("进入了执行");
            PractitionerApi();
            System.out.println("执行完excel生成表1");
            RoadtransportvehiclesApi();
            System.out.println("执行完excel生成表2");
            RoadtransportApi();
            System.out.println("执行完excel生成表3");
            HeavygeneralcargoApi();
            System.out.println("执行完excel生成表4");
            HouseholdinformationApi();
            System.out.println("执行完excel生成表5");
            OccupationalrequirementsApi();
            System.out.println("执行完excel生成表6");
            BusinessoperationApi();
            System.out.println("执行完excel生成表7");
            //返回 执行是否成功
            return "数据录入成功";
//        }catch (Exception e){
//            e.printStackTrace();
//            throw new RuntimeException("数据录入失败");
//        }
    }

    /*********************************************************************************************/
    //所有调用方法区
    void Practitioner() throws JsonProcessingException {
        try{
            System.out.println("进入了数据获取");
            //定义第一次访问的页码
            Integer page = 1;
            //调用数据获取方法
            Boolean mybit = getPractitioner(page);
            //循环遍历
            while (mybit == false){
                System.out.println("进入了数据录入");
                //每次访问页数+1
                page+=1;
                //我的循环判断值每次重新赋值
                mybit = getPractitioner(page);
            }
            System.out.println("Practitioner数据正常录入完毕");
        }catch (Exception e){
            System.out.println("我正在控制台打印我的异常");
            e.printStackTrace();
        }
    }

    //创建判断方法
    public Boolean getPractitioner(Integer page) throws JsonProcessingException {
        //访问内部拿到指定的json字符串
        String str = this.data.getData7(page.toString(),"1000","500222");
        //json识别
        ObjectMapper objectMapper = new ObjectMapper();
        //转换
        PractitionerVo practitionerVo = objectMapper.readValue(str, PractitionerVo.class);
        //打印提示
        System.out.println("从业人员基础信息500222录入条数：" + practitionerVo.getData().getList().size());
        //执行添加sql语句
        practitionerService.saveBatch(practitionerVo.getData().getList());
        //返回查询数据
        return (page*1000) > practitionerVo.getData().getTotalItem() ? true:false;
    }

    /*********************************************************************************************/

    void Businessoperation() throws JsonProcessingException {
        try{
            //定义第一次访问的页码
            Integer page = 1;
            //调用数据获取方法
            Boolean mybit = getBusinessoperation(page);
            //循环遍历
            while (mybit == false){
                //每次访问页数+1
                page+=1;
                //我的循环判断值每次重新赋值
                mybit = getBusinessoperation(page);
            }
            System.out.println("Businessoperation交通局数据正常录入完毕");

            //定义第一次访问的页码
            Integer page2 = 1;
            //调用数据获取方法
            Boolean mybit2 = getBusinessoperation2(page2);
            //循环遍历
            while (mybit2 == false){
                //每次访问页数+1
                page2+=1;
                //我的循环判断值每次重新赋值
                mybit2 = getBusinessoperation2(page2);
            }
            System.out.println("Businessoperation运管处数据正常录入完毕");
        }catch (Exception e){
            throw new RuntimeException("数据录入异常");
        }
    }

    //创建判断方法
    public Boolean getBusinessoperation(Integer page) throws JsonProcessingException {
        //访问内部拿到指定的json字符串
        String str = this.data.getData6(page.toString(),"1000","綦江区交通局");
        //json识别
        ObjectMapper objectMapper = new ObjectMapper();
        //转换
        BusinessoperationVo businessoperationVo = objectMapper.readValue(str, BusinessoperationVo.class);
        //打印提示
        System.out.println("业户经营许可证基础信息交通局录入数据条数：" + businessoperationVo.getData().getList().size());
        //执行添加sql语句
        businessoperationService.saveBatch(businessoperationVo.getData().getList());
        //返回查询数据
        return (page*1000) > businessoperationVo.getData().getTotalItem() ? true:false;
    }

    //创建判断方法
    public Boolean getBusinessoperation2(Integer page) throws JsonProcessingException {
        //访问内部拿到指定的json字符串
        String str = this.data.getData6(page.toString(),"1000","綦江区运管处");
        //json识别
        ObjectMapper objectMapper = new ObjectMapper();
        //转换
        BusinessoperationVo businessoperationVo = objectMapper.readValue(str, BusinessoperationVo.class);
        //打印提示
        System.out.println("业户经营许可证基础信息运管处录入数据条数：" + businessoperationVo.getData().getList().size());
        //执行添加sql语句
        businessoperationService.saveBatch(businessoperationVo.getData().getList());
        //返回查询数据
        return (page*1000) > businessoperationVo.getData().getTotalItem() ? true:false;
    }

    /*********************************************************************************************/

    void Occupationalrequirements() throws JsonProcessingException {
        //定义第一次访问的页码
        Integer page = 1;
        //调用数据获取方法
        Boolean mybit = getOccupationalrequirements(page);
        //循环遍历
        while (mybit == false){
            //每次访问页数+1
            page+=1;
            //我的循环判断值每次重新赋值
            mybit = getOccupationalrequirements(page);
        }
        System.out.println("Occupationalrequirements数据正常录入完毕");
    }

    //创建判断方法
    public Boolean getOccupationalrequirements(Integer page) throws JsonProcessingException {
        //访问内部拿到指定的json字符串
        String str = this.data.getData5(page.toString(),"1000","500222");
        //json识别
        ObjectMapper objectMapper = new ObjectMapper();
        //转换
        OccupationalrequirementsVo occupationalrequirementsVo = objectMapper.readValue(str, OccupationalrequirementsVo.class);
        //打印提示
        System.out.println("从业资格证信息500222录入数据条数：" + occupationalrequirementsVo.getData().getList().size());
        //执行添加sql语句
        occupationalrequirementsService.saveBatch(occupationalrequirementsVo.getData().getList());
        //返回查询数据
        return (page*1000) > occupationalrequirementsVo.getData().getTotalItem() ? true:false;
    }

    /*********************************************************************************************/

    void Householdinformation() throws JsonProcessingException {
        //定义第一次访问的页码
        Integer page = 1;
        //调用数据获取方法
        Boolean mybit = getHouseholdinformation(page);
        //循环遍历
        while (mybit == false){
            //每次访问页数+1
            page+=1;
            //我的循环判断值每次重新赋值
            mybit = getHouseholdinformation(page);
        }
        System.out.println("Householdinformation数据正常录入完毕");
    }

    //创建判断方法
    public Boolean getHouseholdinformation(Integer page) throws JsonProcessingException {
        //访问内部拿到指定的json字符串
        String str = this.data.getData4(page.toString(),"1000","500222");
        //json识别
        ObjectMapper objectMapper = new ObjectMapper();
        //转换
        HouseholdinformationVo householdinformationVo = objectMapper.readValue(str, HouseholdinformationVo.class);
        //打印提示
        System.out.println("业户基础信息500222录入数据条数：" + householdinformationVo.getData().getList().size());
        //执行添加sql语句
        householdinformationService.saveBatch(householdinformationVo.getData().getList());
        //返回查询数据
        return (page*1000) > householdinformationVo.getData().getTotalItem() ? true:false;
    }

    /*********************************************************************************************/
    void Heavygeneralcargo() throws JsonProcessingException {
        //定义第一次访问的页码
        Integer page = 1;
        //调用数据获取方法
        Boolean mybit = getHeavygeneralcargo(page);
        //循环遍历
        while (mybit == false){
            //每次访问页数+1
            page+=1;
            //我的循环判断值每次重新赋值
            mybit = getHeavygeneralcargo(page);
        }
        System.out.println("Heavygeneralcargo数据正常录入完毕");
    }

    //创建判断方法
    public Boolean getHeavygeneralcargo(Integer page) throws JsonProcessingException {
        //访问内部拿到指定的json字符串
        String str = this.data.getData2(page.toString(),"1000","500222");
        //json识别
        ObjectMapper objectMapper = new ObjectMapper();
        //转换
        HeavygeneralcargoVo heavygeneralcargoVo = objectMapper.readValue(str, HeavygeneralcargoVo.class);
        //打印提示
        System.out.println("本市重型普货车辆专题基础信息500222录入数据条数：" + heavygeneralcargoVo.getData().getList().size());
        //执行添加sql语句
        heavygeneralcargoService.saveBatch(heavygeneralcargoVo.getData().getList());
        //返回查询数据
        return (page*1000) > heavygeneralcargoVo.getData().getTotalItem() ? true:false;
    }

    /*********************************************************************************************/
    void Roadtransport() throws JsonProcessingException {
        try{
            //定义第一次访问的页码
            Integer page = 1;
            //调用数据获取方法
            Boolean mybit = getRoadtransport(page);
            //循环遍历
            while (mybit == false){
                //每次访问页数+1
                page+=1;
                //我的循环判断值每次重新赋值
                mybit = getRoadtransport(page);
            }
            System.out.println("Roadtransport交通局数据正常录入完毕");

            //定义第一次访问的页码
            Integer page2 = 1;
            //调用数据获取方法
            Boolean mybit2 = getRoadtransport2(page2);
            //循环遍历
            while (mybit2 == false){
                //每次访问页数+1
                page2+=1;
                //我的循环判断值每次重新赋值
                mybit2 = getRoadtransport2(page2);
            }
            System.out.println("运管处数据正常录入完毕");
        }catch (Exception e){
            throw new RuntimeException("数据录入异常");
        }
    }

    //创建判断方法
    public Boolean getRoadtransport(Integer page) throws JsonProcessingException {
        //访问内部拿到指定的json字符串
        String str = this.data.getData(page.toString(),"1000","綦江区交通局");
        //json识别
        ObjectMapper objectMapper = new ObjectMapper();
        //转换
        RoadtransportVo roadtransportVo = objectMapper.readValue(str, RoadtransportVo.class);
        //打印提示
        System.out.println("业户经营许可证基础信息交通局录入数据条数：" + roadtransportVo.getData().getList().size());
        //执行添加sql语句
        roadtransportService.saveBatch(roadtransportVo.getData().getList());
        //返回查询数据
        return (page*1000) > roadtransportVo.getData().getTotalItem() ? true:false;
    }

    //创建判断方法
    public Boolean getRoadtransport2(Integer page) throws JsonProcessingException {
        //访问内部拿到指定的json字符串
        String str = this.data.getData(page.toString(),"1000","綦江区运管处");
        //json识别
        ObjectMapper objectMapper = new ObjectMapper();
        //转换
        RoadtransportVo roadtransportVo = objectMapper.readValue(str, RoadtransportVo.class);
        //打印提示
        System.out.println("业户经营许可证基础信息运管处录入数据条数：" + roadtransportVo.getData().getList().size());
        //执行添加sql语句
        roadtransportService.saveBatch(roadtransportVo.getData().getList());
        //返回查询数据
        return (page*1000) > roadtransportVo.getData().getTotalItem() ? true:false;
    }

    /*********************************************************************************************/

    void Roadtransportvehicles() throws JsonProcessingException {
        //定义第一次访问的页码
        Integer page = 1;
        //调用数据获取方法
        Boolean mybit = getRoadtransportvehicles(page);
        //循环遍历
        while (mybit == false){
            //每次访问页数+1
            page+=1;
            //我的循环判断值每次重新赋值
            mybit = getRoadtransportvehicles(page);
        }
        System.out.println("Roadtransportvehicles数据正常录入完毕");
    }

    //创建判断方法
    public Boolean getRoadtransportvehicles(Integer page) throws JsonProcessingException {
        //访问内部拿到指定的json字符串
        String str = this.data.getData3(page.toString(),"1000","500222");
        //json识别
        ObjectMapper objectMapper = new ObjectMapper();
        //转换
        RoadtransportvehiclesVo roadtransportvehiclesVo = objectMapper.readValue(str, RoadtransportvehiclesVo.class);
        //打印提示
        System.out.println("道路运输车辆基础信息500222录入数据条数：" + roadtransportvehiclesVo.getData().getList().size());
        //执行添加sql语句
        roadtransportvehiclesService.saveBatch(roadtransportvehiclesVo.getData().getList());
        //返回查询数据
        return (page*1000) > roadtransportvehiclesVo.getData().getTotalItem() ? true:false;
    }

    /*********************************************************************************************/

    /**
     * 每日消息推送
     */
    @GetMapping("/sendExcel")
//    @ApiOperation(value = "连接外网运政数据推送")
    public void sendExcel() throws JsonProcessingException {
        log.info("进入了执行");
        PractitionerApi();
        System.out.println("执行完excel生成表1");
        RoadtransportvehiclesApi();
        System.out.println("执行完excel生成表2");
        RoadtransportApi();
        System.out.println("执行完excel生成表3");
        HeavygeneralcargoApi();
        System.out.println("执行完excel生成表4");
        HouseholdinformationApi();
        System.out.println("执行完excel生成表5");
        OccupationalrequirementsApi();
        System.out.println("执行完excel生成表6");
        BusinessoperationApi();
        System.out.println("执行完excel生成表7");
        //推送
        sendQQExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\业户基础信息.xlsx");
        sendQQExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\业户经营许可证基础信息.xlsx");
        sendQQExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\从业人员基础信息.xlsx");
        sendQQExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\从业资格证.xlsx");
        sendQQExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\本市重型普货车辆专题基础信息.xlsx");
        sendQQExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\道路运输经营许可信息.xlsx");
        sendQQExcel("C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\道路运输车辆基础信息.xlsx");
    }


    void sendQQExcel(String ExcelAdd){
        // 设置您的QQ邮箱地址  调用qq邮箱进行消息推送excel
        final String username = "3608447061@qq.com";
        // 设置您的QQ邮箱授权码
        final String password = "gllnwakhmxzedacg";
        // 创建Properties对象，用于设置邮件相关属性
        Properties props = new Properties();
        // 设置QQ邮箱SMTP服务器地址
        props.put("mail.smtp.host", "smtp.qq.com");
        // 设置QQ邮箱SMTP服务器端口
        props.put("mail.smtp.port", "587");
        // 启用SMTP身份验证
        props.put("mail.smtp.auth", "true");
        // 启用TLS加密
        props.put("mail.smtp.starttls.enable", "true");
        Session session = Session.getInstance(props, new javax.mail.Authenticator() {
            // 实现获取密码验证
            protected PasswordAuthentication getPasswordAuthentication() {
                // 返回用户名和密码的验证信息
                return new PasswordAuthentication(username, password);
            }
        });
        try {
            // 创建邮件消息
            Message message = new MimeMessage(session);
            // 设置发件人邮箱地址
            message.setFrom(new InternetAddress(username));
            // 设置收件人邮箱地址
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("1608494258@qq.com"));
            // 设置邮件主题
            message.setSubject("每日Excel推搡");
//            message.setSubject("验证码推送" + new Date());
            // 创建消息主体
            BodyPart messageBodyPart = new MimeBodyPart();
            // 设置邮件内容
            messageBodyPart.setText("Excel");
            // 创建附件
            MimeBodyPart attachmentPart = new MimeBodyPart();
            // 设置Excel文件路径
            String filename = ExcelAdd;
            //创建文件数据源
            DataSource source = new FileDataSource(filename);
            //设置数据处理程序
            attachmentPart.setDataHandler(new DataHandler(source));
            // 设置附件文件名
            attachmentPart.setFileName(new File(filename).getName());
            // 组合消息部分
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messageBodyPart);
            multipart.addBodyPart(attachmentPart);
            // 设置消息内容为组合部分
            message.setContent(multipart);
            // 发送邮件
            Transport.send(message);
            // 输出邮件发送成功消息
            log.info("Email with attachment sent successfully.");
        } catch (MessagingException e) {
            // 捕获并抛出邮件发送异常
            throw new RuntimeException(e);
        }
    }




    /**********************************************************************************************************/
    //创建数据接收集合 从业人员
    private static List<Practitioner> practitionerList = new LinkedList<>();

    public void PractitionerApi() throws JsonProcessingException {
        //修改后
        this.practitionerList = practitionerService.list(null);
        //错误地方
//        List<Practitioner> list = practitionerService.list(null);

        System.out.println(this.practitionerList.size() + "从业人员基础信息发送数据总行数");
        //生成excel文件
        String fileName = "C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\从业人员基础信息.xlsx";
        //表头字体颜色map 1为user中索引位置
        Map<Integer,Short> colorMap=new HashMap<>();
        //颜色
        colorMap.put(1, IndexedColors.BLUE.index);
        //获取当前日期
        LocalDate currentDate = LocalDate.now();
        System.out.println(currentDate.getDayOfMonth() + "从业人员基础信息");
        //路径
        EasyExcel.write(fileName, Practitioner.class).sheet(currentDate.getDayOfMonth() + "从业人员基础信息").doWrite(this.practitionerList);
        //调用结束后将list赋值为null
        this.practitionerList = null;
    }
    /**********************************************************************************************************/
    //创建接收数据集合 业户经营许可证基础信息
    private static List<Businessoperation> businessoperationList = new LinkedList<>();
    public void BusinessoperationApi() throws JsonProcessingException {
        this.businessoperationList = businessoperationService.list(null);
        System.out.println(this.businessoperationList.size() + "从业人员基础信息发送数据总行数");
        //生成excel文件
        String fileName = "C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\业户经营许可证基础信息.xlsx";
        //表头字体颜色
        Map<Integer,Short> colorMap=new HashMap<>();
        //颜色
        colorMap.put(1, IndexedColors.BLUE.index);
        //获取当前日期
        LocalDate currentDate = LocalDate.now();
        System.out.println(currentDate.getDayOfMonth() + "业户经营许可证基础信息");
        //路径
        EasyExcel.write(fileName, Businessoperation.class).sheet(currentDate.getDayOfMonth() + "业户经营许可证基础信息").doWrite(this.businessoperationList);
        //调用结束后将list赋值为null
        this.businessoperationList = null;
    }

    /**********************************************************************************************************/
    //创建数据接收集合 从业人员
    private static List<Occupationalrequirements> occupationalrequirementsList = new LinkedList<>();
    //从业资格证信息
    public void OccupationalrequirementsApi() throws JsonProcessingException {
        this.occupationalrequirementsList = occupationalrequirementsService.list(null);
        System.out.println(this.occupationalrequirementsList.size() + "从业人员基础信息发送数据总行数");
        //生成excel文件
        String fileName = "C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\从业资格证.xlsx";
        //表头字体颜色
        Map<Integer,Short> colorMap=new HashMap<>();
        //颜色
        colorMap.put(1, IndexedColors.BLUE.index);
        //获取当前日期
        LocalDate currentDate = LocalDate.now();
        //路径
        EasyExcel.write(fileName, Occupationalrequirements.class).sheet(currentDate.getDayOfMonth() + "从业资格证").doWrite(this.occupationalrequirementsList);
        //调用结束后将list赋值为null
        this.occupationalrequirementsList = null;
    };

    /**********************************************************************************************************/
    //创建业户基础信息初始化集合
    private static List<Householdinformation> householdinformationList = new LinkedList<>();
    //业户基础信息
    public void HouseholdinformationApi() throws JsonProcessingException {
        this.householdinformationList = householdinformationService.list(null);
        System.out.println(this.householdinformationList.size() + "从业人员基础信息发送数据总行数");
        //生成excel文件
        String fileName = "C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\业户基础信息.xlsx";
        //表头字体颜色
        Map<Integer,Short> colorMap=new HashMap<>();
        //颜色
        colorMap.put(1, IndexedColors.BLUE.index);
        //获取当前日期
        LocalDate currentDate = LocalDate.now();
        //路径
        EasyExcel.write(fileName, Householdinformation.class).sheet(currentDate.getDayOfMonth() + "业户基础信息").doWrite(this.householdinformationList);
        //调用结束后将list赋值为null
        this.householdinformationList = null;
    };
    /**********************************************************************************************************/
    //创建初始化集合
    private static List<Heavygeneralcargo> heavygeneralcargoList = new LinkedList<>();
    //本市重型普货车辆专题基础信息
    public void HeavygeneralcargoApi() throws JsonProcessingException {
        this.heavygeneralcargoList = heavygeneralcargoService.list( null);
        System.out.println(this.heavygeneralcargoList.size() + "从业人员基础信息发送数据总行数");
        //生成excel文件
        String fileName = "C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\本市重型普货车辆专题基础信息.xlsx";
        //表头字体颜色
        Map<Integer,Short> colorMap=new HashMap<>();
        //颜色
        colorMap.put(1, IndexedColors.BLUE.index);
        //获取当前日期
        LocalDate currentDate = LocalDate.now();
        //路径
        EasyExcel.write(fileName, Heavygeneralcargo.class).sheet(currentDate.getDayOfMonth() + "本市重型普货车辆专题基础信息").doWrite(this.heavygeneralcargoList);
        //调用结束后将list赋值为null
        this.heavygeneralcargoList = null;
    };

    /**********************************************************************************************************/
    //创建初始化集合
    private static List<Roadtransport> roadtransportList = new ArrayList<>(1000000);
    //道路运输经营许可信息
    public void RoadtransportApi() throws JsonProcessingException {
        this.roadtransportList = roadtransportService.list(null);
        System.out.println(this.roadtransportList.size() + "从业人员基础信息发送数据总行数");
        //生成excel文件
        String fileName = "C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\道路运输经营许可信息.xlsx";
        //表头字体颜色
        Map<Integer,Short> colorMap=new HashMap<>();
        //颜色
        colorMap.put(1, IndexedColors.BLUE.index);
        //获取当前日期
        LocalDate currentDate = LocalDate.now();
        //路径
        EasyExcel.write(fileName, Roadtransport.class).sheet(currentDate.getDayOfMonth() + "道路运输经营许可信息").doWrite(this.roadtransportList);
        //调用结束后将list赋值为null
        this.roadtransportList = null;
    };
    /**********************************************************************************************************/
    @Autowired
    private RoadtransportvehiclesMapper roadtransportvehiclesMapper;
    //创建初始化集合
    private static List<Roadtransportvehicles> roadtransportvehiclesList = new LinkedList<>();
    //调用 道路运输车辆基础信息
    public void RoadtransportvehiclesApi() throws JsonProcessingException {
        //此处sql是通过时间排序取出离现在时间最近的一条数据通过车辆进行分组
        this.roadtransportvehiclesList = roadtransportvehiclesMapper.getAllList();
        System.out.println(this.roadtransportvehiclesList.size() + "从业人员基础信息发送数据总行数");
        //生成excel文件
        String fileName = "C:\\Users\\Administrator\\Desktop\\IR数据自动获取代码文件\\道路运输车辆基础信息.xlsx";
        //表头字体颜色
        Map<Integer,Short> colorMap=new HashMap<>();
        //颜色
        colorMap.put(1, IndexedColors.BLUE.index);
        //获取当前日期
        LocalDate currentDate = LocalDate.now();
        //路径
        EasyExcel.write(fileName, Roadtransportvehicles.class).sheet(currentDate.getDayOfMonth() + "道路运输车辆基础信息").doWrite(this.roadtransportvehiclesList);
        //调用结束后将list赋值为null
        this.roadtransportvehiclesList = null;
    };

}

